/**
 * Created by ptt on 2016/5/27/0027.
 */
define(["../maintools/Controller.js", "./tpl.js", "./dataHandle.js"], function (Controller, tpl, handle) {
    //initial searchbox has bug for global value jQuery
    tpl = tpl.detailpage;
    Controller = Controller.Controller;
    var Trigger = Controller.create({
        //elements: {
        //    "button.js-search": "searchButton",
        //    "input.js-search": "searchBox"
        //},
        events: {
            "click a": "lookupDetail"
        },
        lookupDetail: function (e) {
            e.preventDefault();
            $('<div class="ifrcontain"></div>').appendTo(document.body).append('<div class="head">'+e.target.innerText+'</div>')
                .append('<iframe border="0" width="100%" height="100%" src=' + e.target.href + '>')
                .append('<span class="closeButton"></span>');
            $("div.ifrcontain").click(function (e) {

            });
            $("div.ifrcontain>span.closeButton").click(function (e) {
                $(this).parent().css({
                    display: "none"
                });
                document.body.removeChild(this.parentNode);
            });
        },
        show: function () {
            this.el.removeClass("hide");
            this.el.css({
                left: "-60px",
                opacity: 0
            });
            this.el.animate({
                left: "25px",
                opacity: 1
            });
        },
        hide: function () {
            this.el.addClass("hide");
        },
        jrt: function () {
            var isDetailShow = false;
            Message_bone.on("showDetail", this.proxy(function (e, data) {
                !isDetailShow && this.show();
                isDetailShow = true;
                this.render(data);
                Message_bone.trigger("closeButtonShow");
            }));
            Message_bone.on("detailHide", this.proxy(function (e, data) {
                this.hide();
                isDetailShow = false;
            }));
        },
        template: "#tdetailpage"
    });
    var trigger = new Trigger("#detailpage");
    trigger.hide();
    return {
        detailpageController: trigger
    }

});